<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="elibrary.*" %>
<%@ page language="java" import="java.util.*"%>
<%@ include file="config.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Request Book</title>
    </head>
    <body>

        <%
        try
        {
	
                //user id fetched from the session and if he is not a valid user then he is redirected to the index page
	
                String uid=(String)session.getAttribute("uid");
                if(uid==null||uid.equals(""))
                {
                        response.sendRedirect("index.jsp");
                }
                DesEncrypter encrypter = new DesEncrypter();
                int uid1 = Integer.parseInt(encrypter.decrypt(uid));
	
                String name=request.getParameter("name");
                String author=request.getParameter("author");
                String publisher=request.getParameter("publisher");
	

                Connection con=null;
                Statement stmt = null;
                ResultSet results = null;

                con=DaoConnection.getcon(connectURL, DBuser, DBpass);
                Statement st=con.createStatement();
	
                //the requested book is entered in the database
	
	
            String str="INSERT INTO REQUEST (UID, BOOKNAME, AUTHOR, PUBLISHER) VALUES("+uid1+",'"+name+"','"+author+"','"+publisher+"')";
            out.println(str);
            st.executeUpdate(str);
            session.setAttribute("message", "Request for new book sent.");
                response.sendRedirect("home.jsp");
		
         }catch(Exception e){
             out.println(e.toString());
             out.println("ERROR!!");
             e.printStackTrace();
         }
        %>

    </body>
</html>